﻿using Blog190311.Areas.Back.Models.DAL;
using Blog190311.Models.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Blog190311.Areas.Back.Controllers
{
    [Authorize]
    public class ArticleController : Controller
    {
        // GET: Back/Article
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 多条件查询
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="Title"></param>
        /// <param name="Type"></param>
        /// <param name="IsPub"></param>
        /// <param name="Tags"></param>
        /// <returns></returns>
        public ActionResult GetArticles(int limit, int page, string Title, string Type, string IsPub, string Tags)
        {
            ArticleService articleser = new ArticleService();
            List<Article> lists = articleser.GetArticles(limit, page, Title, Type, IsPub, Tags);
            int num = articleser.GetCount(Title, Type, IsPub, Tags);
            return Json(new { code = 0, msg = "", count = num, data = lists }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="articles"></param>
        /// <returns></returns>
        public ActionResult Addarticle(Article articles)
        {
            ArticleService articleser = new ArticleService();
            int num = articleser.Addarticle(articles);
            return Content(num.ToString());
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public ActionResult Updatearticle(Article articl)
        {
            ArticleService articleser = new ArticleService();
            int num = articleser.UpdateArticle(articl);
            return Content(num.ToString());
        }

        public ActionResult Edit(int Id)
        {
            ArticleService articleser = new ArticleService();
            Article lists = articleser.GetArticleId(Id);
            return View(lists);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult DeleteArticle(int Id)
        {
            ArticleService articleser = new ArticleService();
            int num = articleser.Delarticle(Id);
            return Content(num.ToString());
        }

        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult Fabu(int Id)
        {
            ArticleService articleser = new ArticleService();
            int num = articleser.Fabu(Id);
            return Content(num.ToString());
        }
    }
}